import { postRequest } from 'components/functions';
import { ChainBO, ChanReqData } from 'pages/tree/model/Interfaces';


export function fetchChainData (reqData:ChanReqData,analyze?: (data: ChainBO[]) => void): void {
  postRequest('/route/route/getAllChain',reqData,analyze)
}

export function getChainTop (data: ChainBO[]): ChainBO {
  let top: ChainBO =  data[0]
  // data.forEach(x => {
  //   if (x.relationNode.codeValueName === '初始结点') {
  //     top = x;
  //     return;
  //   }
  // });
  return top;
}

export function getTickedObjByIds (chainIds: string[],allChainBo:ChainBO[]): ChainBO[] {
  let filterdChainBo: ChainBO[] =  []
  chainIds.forEach((x:string) => {
    allChainBo.forEach((y:ChainBO) => {
      if (y.relationNode.id === x)
        filterdChainBo.push(y)
    })
  })
  return filterdChainBo;
}
